/**
 * 
 */
package com.et114.modules.org.services;

//import com.et114.modules.org.vo.RoleVo;
//import com.et114.modules.org.vo.UserVo;
//import com.et114.modules.org.vo.TitleMsgVo;
//import com.et114.modules.org.vo.IResource;
//import com.et114.modules.org.vo.FunctionVo;
//import com.et114.modules.org.vo.FuncComponentVo;
import com.et114.core.exception.CheckException;
import com.et114.core.services.impl.BaseServicesImpl;
import com.et114.modules.org.dao.AclDAO;
import com.et114.modules.org.vo.AclVo;
//import com.et114.components.acegi.Constants;
//import com.et114.components.acegi.cache.AcegiCacheManager;

import org.springframework.util.Assert;

/**
 * @author guanhw
 */
public class AclManager extends BaseServicesImpl {
	private AclDAO				aclDAO;
	public void setAclDAO ( AclDAO aclDAO ) {
		this.aclDAO = aclDAO;
	}

	/**
	 * 
	 * @param acl
	 * @throws CheckException
	 */
	public void deleteAcl ( AclVo acl ) throws CheckException {
		aclDAO.deleteAcl ( acl );
	}
	
	/**
	 * 
	 * @param roleId
	 * @throws CheckException
	 */
	public void deleteAclByRoleId ( Long roleId , Long operUser ) throws CheckException {
		aclDAO.deleteAclByRoleId ( roleId , operUser );
	}
	
	/**
	 * 
	 */
	public void deleteAclByUserId ( Long userId , Long operUser ) throws CheckException {
		aclDAO.deleteAclByUserId ( userId , operUser );
	}
	
	/**
	 * 
	 * @param titleId
	 * @throws CheckException
	 */
	public void deleteAclByTitleId ( Long titleId , Long operUser ) throws CheckException {
		aclDAO.deleteAclByTitleId ( titleId , operUser );
	}
	
	/**
	 * 
	 * @param id
	 * @throws CheckException
	 */
	public void deleteAclByFuncId ( Long id , Long operUser ) throws CheckException {
		aclDAO.deleteAclByFuncId ( id  , operUser );
	}
	
	/**
	 * 
	 * @param id
	 * @throws CheckException
	 */
	public void deleteAclByMethodId ( Long id , Long operUser ) throws CheckException {
		aclDAO.deleteAclByMethodId ( id , operUser );
	}
	
	/**
	 * 
	 * @param id
	 * @throws CheckException
	 */
	public void deleteAclByFuncElementId ( Long id , Long operUser ) throws CheckException {
		aclDAO.deleteAclByFuncElementId ( id , operUser );
	}
	
	/**
	 * 0:存在 1:授权成功
	 * 
	 * @param acl
	 * @return
	 * @throws CheckException
	 */
	public  void doAuthorize ( AclVo acl ) throws CheckException {
		Assert.notNull ( acl.getResourceType ( ) , "ResourceType is Null ！" );
		Assert.notNull ( acl.getPrincipalType ( ) , "PrincipalType is Null !" );
		Assert.notNull ( acl.getPrincipalId ( ) , "PrincipalId is Null !" );
		Assert.notNull ( acl.getResourceId ( ) , "ResourceId is Null !" );
		aclDAO.doAuthorize ( acl );
		/*
		if ( countloadAuthorizes( acl ) == 0  ) 
		else logger.info ( "acl write warn !" ) ;*/
	}
	
	
	public int countloadAuthorizes( AclVo acl ) throws CheckException {
		return aclDAO.countloadAuthorizes ( acl ) ; 
	}
}
